package com.nengchuan.kbms.dfs.controller.center;


import com.nengchuan.kbms.dfs.entity.dto.PermissionFileDTO;
import com.nengchuan.kbms.dfs.entity.vo.PermissionFileListVO;
import com.nengchuan.kbms.dfs.service.PermissionFileService;
import com.nengchuan.model.model.WrappedResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * t_permission_file（文件权限） 前端控制器
 * </p>
 *
 * @author abe
 * @since 2020-04-09
 */
@RestController
@RequestMapping("/center/permission")
@Api(tags = "知识库数据后台管理 > 数据中心 > 文件夹权限分配 【已完成】")
public class PermissionController {

    @Autowired
    private PermissionFileService permissionFileService;

    @PostMapping("/list")
    @ApiOperation(value = "列表")
    public WrappedResult<List<PermissionFileListVO>> list(@ApiParam(value = "文件（文件夹）id", required = true) @RequestParam Long id) {
        return WrappedResult.success(permissionFileService.list(id));
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增")
    public WrappedResult<Long> save(@RequestBody PermissionFileDTO dto) {
        return WrappedResult.success(permissionFileService.savePermission(dto));
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public WrappedResult<Boolean> update(@RequestBody PermissionFileDTO dto) {
        return WrappedResult.success(permissionFileService.updatePermission(dto));
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public WrappedResult<Boolean> delete(@ApiParam(value = "文件权限id", required = true) @RequestParam Serializable id) {
        return WrappedResult.success(permissionFileService.remove(id));
    }

}
